import { BaseController } from '@/api/BaseController';
import { RequestOption } from '@/common/http/types';
import { DictData, DictionaryBase } from '@/common/staticDict/types';
import { ANY_OBJECT } from '@/types/generic';
import { API_CONTEXT } from '../config';

export default class DictionaryController extends BaseController {
  static dictSysRole(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/sysRole/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('角色字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  // 全局编码字典
  static dictGlobalDict(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/globalDict/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase(
            '编码字典',
            (res.data || []).map(item => {
              return {
                ...item,
                // 设置已禁用编码字典数据项
                disabled: item.status === 1,
              };
            }),
          );
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictGlobalDictByIds(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/globalDict/listDictByIds', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('编码字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictAllMenu(params: ANY_OBJECT, httpOptions?: RequestOption): Promise<DictionaryBase> {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/sysMenu/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('菜单字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictSysMenu(params: ANY_OBJECT, httpOptions?: RequestOption): Promise<DictionaryBase> {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/sysMenu/listMenuDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('菜单字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictDeptPost(params: ANY_OBJECT, httpOptions?: RequestOption): Promise<ANY_OBJECT[]> {
    return new Promise((resolve, reject) => {
      super
        .get<ANY_OBJECT[]>(
          API_CONTEXT + '/upms/sysDept/listSysDeptPostWithRelation',
          params,
          httpOptions,
        )
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysPost(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/upms/sysPost/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('岗位字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictReportDblink(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/report/reportDblink/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('数据库链接', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictReportDict(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>(API_CONTEXT + '/report/reportDict/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('字典管理', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictSysUser(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/upms/sysUser/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('用户字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysDept(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/upms/sysDept/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('部门字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysDeptByParentId(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/upms/sysDept/listDictByParentId', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('部门字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAreaCode(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/areaCode/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('行政区划', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAreaCodeByParentId(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/areaCode/listDictByParentId', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('行政区划', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAddAreaCode(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('', params, httpOptions);
  }
  static dictDeleteAreaCode(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('', params, httpOptions);
  }
  static dictUpdateAreaCode(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('', params, httpOptions);
  }
  static dictReloadAreaCodeCachedData(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.get<DictData[]>('', params, httpOptions);
  }
  static dictCourse(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/course/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('课程字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictKnowledge(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/knowledge/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('知识点字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictStudent(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/student/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('学生字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictTeacher(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/teacher/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('老师字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictTestFlowFirstParty(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/testFlowFirstParty/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('甲方字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictTestFlowSecondParty(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/testFlowSecondParty/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('乙方字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictTestFlowProduct(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/testFlowProduct/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('产品字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictMaterialEdition(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/materialEdition/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('教材版本', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictMaterialEditionAll(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise((resolve, reject) => {
      super
        .get('/admin/app/materialEdition/listAll', params, httpOptions)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAddMaterialEdition(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/materialEdition/add', params, httpOptions);
  }
  static dictDeleteMaterialEdition(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/materialEdition/delete', params, httpOptions);
  }
  static dictUpdateMaterialEdition(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/materialEdition/update', params, httpOptions);
  }
  static dictReloadMaterialEditionCachedData(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.get<DictData[]>(
      '/admin/app/materialEdition/reloadCachedData',
      params,
      httpOptions,
    );
  }
  static dictSpeciality(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise<DictionaryBase>((resolve, reject) => {
      super
        .get<DictData[]>('/admin/app/speciality/listDict', params, httpOptions)
        .then(res => {
          const dictData = new DictionaryBase('特长字典', res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSpecialityAll(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return new Promise((resolve, reject) => {
      super
        .get('/admin/app/speciality/listAll', params, httpOptions)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAddSpeciality(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/speciality/add', params, httpOptions);
  }
  static dictDeleteSpeciality(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/speciality/delete', params, httpOptions);
  }
  static dictUpdateSpeciality(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<DictData[]>('/admin/app/speciality/update', params, httpOptions);
  }
  static dictReloadSpecialityCachedData(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.get<DictData[]>('/admin/app/speciality/reloadCachedData', params, httpOptions);
  }
}
